#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<cstring>
using namespace std;
const int N = 210;
int f[N][N];
int g[N][N];
int s[N];
int n;
int main()
{
    cin >> n;
    int m = n + n;
    for (int i = 1; i <= n; i++)
    {
        cin >> s[i];
        s[i + n] = s[i];
    }
    memset(f, 0x3f, sizeof(f));
    memset(g, -0x3f, sizeof(g));
    for (int i = 1; i <= m; i++)
    {
        s[i] += s[i - 1];
    }
    for (int i = 1; i <= m; i++)
    {
        f[i][i] = g[i][i] = 0;
    }
    for (int len = 1; len <= n; len++)
    {
        for (int i = 1; i + len - 1 <= m; i++)
        {
            int j = i + len - 1;
            int cnt = s[j] - s[i - 1];
            for (int k = i; k < j; k++)
            {
                f[i][j] = min(f[i][j], f[i][k] + f[k + 1][j] + cnt);
                g[i][j] = max(g[i][j], g[i][k] + g[k + 1][j] + cnt);
            }
        }
    }
    int ret1 = 0x3f3f3f3f;
    int ret2 = -0x3f3f3f3f;
    for (int i = 1; i <= n; i++)
    {
        ret1 = min(ret1, f[i][i + n - 1]);
        ret2 = max(ret2, g[i][i + n - 1]);
    }
    cout << ret1 << endl;
    cout << ret2 << endl;
    return 0;
}